//14.5 - Pirates.cpp - Mark Lee - Prima Publishing #include #include "ddraw.h" #include "ddutil.h" #include "Movement.h" #include "Ship.h" #include "globals.h" #include "drawing.h" #include "Towns.h" Ship* ship; //the player's ship #include "Ship.cpp" #include "globals.cpp" #include "Movement.cpp" #include "Towns.cpp" #include "drawing.cpp" int WINAPI WinMain(/*Win32 entry-point routine */ HINSTANCE hInst, HINSTANCE hPreInst, LPSTR lpszCmdLine, int nCmdShow ) { //call InitApp to do initialization InitApp(hInst, nCmdShow); //call DoEventLoop to handle the event loop return DoEventLoop(); } /*callback procedure */ LRESULT CALLBACK WndProc( HWND hWnd, UINT messg, WPARAM wParam, LPARAM lParam ) //this function processes user input //and the timers used to run the game { static bool inCity = false; //stores if player is in a city switch(messg) //figure out which message is being sent { case WM_CREATE: //if the winow is being created //do DirectX initialization InitializeDirectX(hWnd); CreateTowns();//create all of the Town objects //The title screen is displayed for //5 seconds (5000 milliseconds) //After this we enter the main part of the game //Set the opening screen timer SetTimer(hWnd,OpeningTimer,5000,NULL); //display the opening screen DisplayScreen(OpeningScreen); break;//end case WM_CREATE //this event is used to get rid of the mouse case WM_SETCURSOR: SetCursor(NULL);//set it to NULL break;//end case WM_SETCURSOR case WM_KEYDOWN: //if a key is pressed //if player is in city then //only the Enter key works if (inCity) { //if the key is Enter then //we exit the city screen if(wParam == VK_RETURN) inCity = false; break; } //handled if city screen, //so treat as normal game now switch(wParam)//figure out which key it is { case VK_UP://the up arrow //inform everyone else //that we should move up moveUp = true; break; case VK_DOWN://the down arrow moveDown = true; break; case VK_LEFT://the left arrow moveLeft = true; break; case VK_RIGHT://the right arrow moveRight = true; break; case VK_SPACE://the space bar //we should fire //note that firing has //not been implemented yet fire = true; break; case VK_ESCAPE://the Esc key //end the main timer KillTimer(hWnd,MainTimer); PostQuitMessage(0);//end the program break; } break;//end case WM_KEYDOWN case WM_KEYUP://if a key is released switch(wParam)//figure out which key { //stop moving if key is released case VK_UP: moveUp = false; break; case VK_DOWN: moveDown = false; break; case VK_LEFT: moveLeft = false; break; case VK_RIGHT: moveRight = false; break; case VK_SPACE: fire = false; break; } break;//end case WM_KEYUP case WM_TIMER://if a timer goes off //if player is in city then don't use the timer if (inCity) break;//exit the WM_TIMER message switch(wParam)//find out which timer is going off { //the timer for the opening screen case OpeningTimer: //start the main timer SetTimer(hWnd,MainTimer,15,NULL); //kill the opening screen timer KillTimer(hWnd,OpeningTimer); //draw the screen for the first time Draw(); break;//exit case OpeningTimer //the timer for the main game case MainTimer: DoMove();//move ship based on input Redraw();//redraw the screen //if player has entered a city if(isInCity(&ship->GetPosition())) { //inform everyone else inCity = true; //display the city screen DisplayScreen(CityScreen); //put the player outside of city radius ship->moveBack(); } break;//end case MainTimer } break;//end case WM_TIMER default: //let Windows handle all other messages return( DefWindowProc( hWnd, messg, wParam, lParam ) ); } return(0);//default return value }